﻿Imports System.Data.OleDb
Imports System.Data
Partial Class DiscussionDetails
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click
        System.Threading.Thread.Sleep(2000)

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("myFirstDatabase").ConnectionString)
        Dim SqlString As String = "Insert into tblDiscussContrib(Author,Discuss_fkid,SubmittedDate,Contribution,Topic) Values (@f1,@f2,@f3,@f4,@f5)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        Dim SubmittedDate As DateTime = Now()
        Dim format As String = "ddd MMM yyyy"
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        ' cmd.Parameters.AddWithValue("@f1", txtAuthor.Text)
        cmd.Parameters.AddWithValue("@f2", Request.Params("ID"))
        cmd.Parameters.AddWithValue("@f3", SubmittedDate.ToString(format))
        cmd.Parameters.AddWithValue("@f4", txtComments.Text)
        cmd.Parameters.AddWithValue("@f5", Request.Params("ID"))
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        'Response.Redirect("DiscussConfirm.aspx")
    End Sub

    Protected Sub btnTag_Click(sender As Object, e As System.EventArgs) Handles btnTag.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("myFirstDatabase").ConnectionString)
        Dim SqlString As String = "Insert into tblDiscussTagJun(Discussion,DissTag) Values(@f1,@f2)"
        oleDbConn.Open()

        For Each cb As ListItem In cbListTag.Items
            If cb.Selected Then
                'here is where the join to the table of tags and articles
                Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
                cmd.CommandType = CommandType.Text
                cmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
                cmd.Parameters.AddWithValue("@f2", cb.Value)
                cmd.ExecuteNonQuery()
            End If
        Next
    End Sub

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("myFirstDatabase").ConnectionString)
            oleDbConn.Open()
            Dim ArtViewSql As String = "INSERT INTO tblDiscussionViewed(Neighbor, Discussion) VALUES(@f1,@f2)"
            Dim cmd As OleDbCommand = New OleDbCommand(ArtViewSql, oleDbConn)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
            cmd.Parameters.AddWithValue("@f2", Request.Params("ID"))
            cmd.ExecuteNonQuery()
        End If
    End Sub
End Class
